<?php

################################################################################################################
Function create_config_mysql($server, $user, $pass, $database, $prefixe)
{
	if (!($fd = fopen("data/config/mysql.php",'w')))
		return (-1);
	$line = '<?php'."\n";
	$line .= '#'." MySQL's Informations ".'#'."\n";
	fputs($fd, $line);
	$line = '$server_mysql = ';
	$line .= '"'.$server.'"';
	$line .= ';';
	$line .= "\n";
	fputs($fd, $line);
	$line = '$user_mysql = ';
	$line .= '"'.$user.'"';
	$line .= ';';
	$line .= "\n";
	fputs($fd, $line);
	$line = '$pass_mysql = ';
	$line .= '"'.$pass.'"';
	$line .= ';';
	$line .= "\n";
	fputs($fd, $line);
	$line = '$database = ';
	$line .= '"'.$database.'"';
	$line .= ';';
	$line .= "\n";
	fputs($fd, $line);
	$line = '$prefix = ';
	$line .= '"'.$prefixe.'"';
	$line .= ';';
	$line .= "\n";
	fputs($fd, $line);
	$line = '?>'."\n";
	fputs($fd, $line);
	
	return(0);
}

################################################################################################################
Function create_config_ldap($server, $domain)
{
	if (!($fd = fopen("data/config/ldap.php",'w')))
		return (-1);
	$line = '<?php'."\n";
	$line .= '#'." LDAP's Informations ".'#'."\n";
	fputs($fd, $line);
	$line = '$server_ldap = ';
	$line .= '"'.$server.'"';
	$line .= ';';
	$line .= "\n";
	fputs($fd, $line);
	$line = '$domain_ldap = ';
	$line .= '"'.$domain.'"';
	$line .= ';';
	$line .= "\n";
	fputs($fd, $line);
	$line = '?>'."\n";
	fputs($fd, $line);
	
	return(0);
}

################################################################################################################
Function create_config_default($title, $subtitle, $auth)
{
	if (!($fd = fopen("data/config/default.php",'w')))
		return (-1);
	$line = '<?php'."\n";
	$line .= '#'." Default's Informations ".'#'."\n";
	fputs($fd, $line);
	$line = '$title = ';
	$line .= '"'.$title.'"';
	$line .= ';';
	$line .= "\n";
	fputs($fd, $line);
	$line = '$subtitle = ';
	$line .= '"'.$subtitle.'"';
	$line .= ';';
	$line .= "\n";
	fputs($fd, $line);
	$line = '$auth = ';
	$line .= '"'.$auth.'"';
	$line .= ';';
	$line .= "\n";
	fputs($fd, $line);
	$line = '?>'."\n";
	fputs($fd, $line);
	
	return(0);
}

################################################################################################################
Function apply_config()
{
	if (!(@copy ($_SESSION['current_path']."/modules/root/index.php", "index.php")))
		return (-1);
	if (!(@copy ($_SESSION['current_path']."/modules/root/login.php", "login.php")))
		return (-1);
	if (!(@copy ($_SESSION['current_path']."/modules/root/profil.php", "profil.php")))
		return (-1);
	if (!(@copy ($_SESSION['current_path']."/modules/root/signup.php", "signup.php")))
		return (-1);
	if (!(@copy ($_SESSION['current_path']."/modules/root/ipage.php", "ipage.php")))
		return (-1);
	if (!(@rename($_SESSION['current_path']."/modules/index", $_SESSION['path_apps']."/index")))
		return (-1);
	if (!(@rename($_SESSION['current_path']."/modules/login", $_SESSION['path_apps']."/login")))
		return (-1);
	if (!(@rename($_SESSION['current_path']."/modules/profil" , $_SESSION['path_apps']."/profil")))
		return (-1);
	if (!(@rename($_SESSION['current_path']."/modules/signup" , $_SESSION['path_apps']."/signup")))
		return (-1);
	if (!(@unlink("data/config/install.php")))
		return (-1);
	@mkdir ("data/users/".$_SESSION[infos_admin]);
	@unlink("install.php");
	return (0);
}

?>